package com.scrum.repository;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.scrum.vos.MessageExceptions;
import com.scrum.vos.User;

@Repository
public class JpaUserRepository extends JpaProjectRepository<User> implements IUserRepository{

	@Override
	public User findUserByAttribute(String attribute, String value) throws Exception{
		
		Query query = null; 
		try {
			query = em.createQuery("FROM User as user WHERE user." + attribute + " = :value");
			query.setParameter("value", value);
			return (User) query.getSingleResult();
			
		} catch (Exception e) {
			throw new Exception(MessageExceptions.USER_NOT_EXIST);
		}		
	}

}
